//百家乐下注页js
//背景音乐开关
	$(".sound").on("click",function(){
	if($(this).hasClass("rotate")){
		$(this).removeClass("rotate")
		 BG_SOUND.stop();
	}else{
		$(this).addClass("rotate")
		 BG_SOUND.play();
	}
})

//系统音乐开关
   $(".systemSound").on("click",function(){
	   if($(this).find(".onSound").length==1){
		   $(".onSound").removeClass("onSound").addClass("offSound")
	   }else{
		   $(".offSound").removeClass("offSound").addClass("onSound")
	   }
   })
   
 //查看帮助
   $(".help").on("click",function(){
	   $(".game-rule-promptbox").show();
   })
   
   //关闭帮助框
   $(".grp-close").on("click",function(){
	   $(".game-rule-promptbox").hide();
   })
   
   // 初始化音乐播放器
   var initAutoMusicPlayer = function() {
			if(isIphone){
				MUSIC_PATH =  "/music/"
			} else {
				MUSIC_PATH =  "/music/android/"
		    }
			var bgMp3 = MUSIC_PATH + "bg.mp3"
			var DownMp3=MUSIC_PATH + "countDown.mp3"
			BG_SOUND = new Howl({
				  src: [bgMp3],
 				  loop: true,
			})
			BG_SOUND.play()
			playAuto(BG_SOUND)
 			Down_SOUND = new Howl({
				  src: [DownMp3],
			})
			
			
 			BET_START_SOUND = new Howl({
				  src: [MUSIC_PATH + "betStart.mp3"],
			})
			BET_END_SOUND = new Howl({
				  src: [MUSIC_PATH + "betEnd.mp3"],
			})	
		}
	
	//切换房间
	$(".roomSwitch").hover(function(){
		$(".room-div").show();
	},function(){
		$(".room-div").hide();
	});
	
	$(".room-div").hover(function(){
		$(".room-div").show();
	},function(){
		$(".room-div").hide();
	});
	
	$(".room-div ul li").on("click",function(){
		var index=$(this).index()+1;
		window.location.href="/pc/bjllot.do?roomid="+index;
		
	})
	
	function backRoom(){
		window.location.href="/pc/bjl.do";
	}
	
	//获取期号
	var getMarkInfo = function(n) {
		var urlPath =  "/b/bjlLotter.do"
		$.ajax({
			url: urlPath,
			type: "post",
			data: {
				tableNumber: roomId,
			},
			success: function(data) {
				issueNumber = data.data.nextIssueNumber
				$(".preiod").text("第"+issueNumber+"期")
				//插入jia硬币
				/*getFakeCoinsFromServer(n)*/
			},
		})
	 }
	
	//获取用户的钱
	var getUserMoneyNumber = function() {
		var urlPath =  "/u/userInfos.do"
			$.ajax({
				url: urlPath,
				type: "post",
				data: {
				},
				success: function(data) {
					$(".balance").val(data.data.balance)
					$(".userName").val(data.data.name)
				},
			})
	} 
	
	
	 // 生产假硬币的辅助函数
	   var insertStaticCoin = function(coin) {
		   var fakeCoin=document.createElement("div")
		   var wanfa=coin.fq1;
		   if(wanfa="he"){
			   wanfa="draw"
		   }if(wanfa="large"){
			   wanfa="big"
		   }if(wanfa="arbitraryPairsx"){
			   wanfa="randomPair"
		   }if(wanfa="perfectPairx"){
			   wanfa="perfectPair"
		   }if(wanfa="zhuangdui"){
			   wanfa="zhuangPair"
		   }if(wanfa="xiandui"){
			   wanfa="xianPair"
		   }
			var $fakeCoin=$(fakeCoin)
		   $(fakeCoin).addClass("class-img-fakeCoins")
		   $("."+wanfa).append(fakeCoin)
		     var leftValue
			   var bottomValue
			   if(coin.ds>=1000 && coin.ds<10000){
				   coin.ds=coin.ds/1000+"千"
				}else if(coin.ds>=10000){
					coin.ds=coin.ds/10000+"万"
				}
		   for(i=0;i<$(".select-jetton li").length;i++){
			   if($(".select-jetton li").eq(i).text()==coin.dianshu){
				   $fakeCoin.css("background","url(/pc-static/img/bjl/chip"+Number(i+1)+".png) no-repeat 100% 100%")
				   leftValue =$(".select-jetton li").eq(i).offset().left+5
				   bottomValue=$(".wappering").height()-$(".select-jetton li").eq(i).offset().top-40
				   $fakeCoin.css("left",leftValue+"px")
				   $fakeCoin.css("bottom",bottomValue+"px")
			   }
		   }
		   var chargeLen= $("."+wanfa).find(".class-img-smallCoin").length;
		   if(chargeLen>6){
				chargeLen=6
			}
			leftValue=$("."+wanfa).offset().left+15
			bottomValue=$(".wappering").height()-$("."+wanfa).offset().top-115+chargeLen*5
			setTimeout(function() {
				$fakeCoin.css("bottom",bottomValue+"px")
				$fakeCoin.css("left",leftValue+"px")
			}, 100)
	   }
	   
	   
	   // 直接插入假硬币(因为用户来晚了)
	   var justSetCoin = function(coin) {
		   /*var newCoin = document.createElement("div")
			var $newCoin=$(newCoin)
			$newCoin.addClass("class-img-smallCoin")
			$(this).append(newCoin)
			$newCoin.css("background","url(/pc-static/img/bjl/chip"+chooseIndex+".png) no-repeat 100% 100%")
			var leftValue=$(".gameCoin-large").offset().left+5
			var bottomValue=$(".wappering").height()-$(".gameCoin-large").offset().top-40
			$newCoin.css("left",leftValue+"px")
			$newCoin.css("bottom",bottomValue+"px")
			var chargeLen=$(that).find(".class-img-smallCoin").length;
			if(chargeLen>6){
				chargeLen=6
			}
			leftValue=$(that).offset().left+15
			bottomValue=$(".wappering").height()-$(that).offset().top-115+chargeLen*5;
			setTimeout(function() {
				$newCoin.css("bottom",bottomValue+"px")
				$newCoin.css("left",leftValue+"px")
			}, 300)*/
			
			var fakeCoin=document.createElement("div")
			var $fakeCoin=$(fakeCoin)
		   $(fakeCoin).addClass("class-img-fakeCoins")
		   $(wanfaObject[coin.wanfa]).append(fakeCoin)
		     var leftValue
			   var bottomValue
			   if(coin.dianshu>=1000 && coin.dianshu<10000){
				   coin.dianshu=coin.dianshu/1000+"千"
				}else if(coin.dianshu>=10000){
					coin.dianshu=coin.dianshu/10000+"万"
				}
		   for(i=0;i<$(".select-jetton li").length;i++){
			   if($(".select-jetton li").eq(i).text()==coin.dianshu){
				   $fakeCoin.css("background","url(/pc-static/img/bjl/chip"+Number(i+1)+".png) no-repeat 100% 100%")
				   leftValue =$(".select-jetton li").eq(i).offset().left+5
				   bottomValue=$(".wappering").height()-$(".select-jetton li").eq(i).offset().top-40
				   $fakeCoin.css("left",leftValue+"px")
				   $fakeCoin.css("bottom",bottomValue+"px")
			   }
		   }
		   var chargeLen= $(wanfaObject[coin.wanfa]).find(".class-img-smallCoin").length;
		   if(chargeLen>6){
				chargeLen=6
			}
			leftValue=$(wanfaObject[coin.wanfa]).offset().left+15
			bottomValue=$(".wappering").height()-$(wanfaObject[coin.wanfa]).offset().top-115+chargeLen*5
			setTimeout(function() {
				$fakeCoin.css("bottom",bottomValue+"px")
				$fakeCoin.css("left",leftValue+"px")
			}, 300)
		  /* var fakeImg = document.createElement("img")
		   fakeImg.src = "/img/caizhong/bjl/coin-" + coin.dianshu + "-2x.png"
		   fakeImg.classList.add("class-img-fakeCoins")
		   fakeImg.classList.add("class-img-mygameCoin")
		   fakeImg.style.top = coin.topValue + "px"
		   fakeImg.style.left = coin.leftValue + "px"*/
		   /*document.querySelector(wanfaObject[coin.wanfa]).insertAdjacentElement("beforeend", fakeImg)*/	   
	   }
	   
	   
	// 时间倒计时时，射入jia硬币
		var getFakeCoinsFromServer = function(n) {
			var urlPath =  "/b/coin.do"
			if (n <= 3) {
				urlPath =  "/b/coin.do"
			}
			/*var xianduiObject = getTopAndLeft(document.querySelector(".class-div-xiandui"))
			var heObject = getTopAndLeft(document.querySelector(".class-div-he"))
			var zhuangduiObject = getTopAndLeft(document.querySelector(".class-div-zhuangdui"))
			var xianObject = getTopAndLeft(document.querySelector(".class-div-wanfa-textXian"))
			var zhuangObject = getTopAndLeft(document.querySelector(".class-div-wanfa-textzhuang"))*/
			var dataObject = {
					ds: issueNumber,
			    	fq: ["xiandui", "he", "zhuangdui", "xian", "zhuang","xiao","da","wanmeiduizi","renyiduizi"],/**/
			    	/*top: [xianduiObject.top, heObject.top, zhuangduiObject.top, xianObject.top, zhuangObject.top],
			    	left: [xianduiObject.left, heObject.left, zhuangduiObject.left, xianObject.left, zhuangObject.left],*/
			    	tableNumber: roomId,
			    	top:[0,0,0,0,0,0,0,0,0],
					left:[0,0,0,0,0,0,0,0,0]
			}
				var newRequest = {
					url: urlPath,
					type: "post",
					data: dataObject,
					success: function(data) {
						var newData = data
						var result = JSON.parse(newData).data
						FAKE_COIN_ARRAY = {}
						for (var i = 0; i < result.length; i++) {
							var item = result[i]
							if (!(item.sj in FAKE_COIN_ARRAY)) {
								FAKE_COIN_ARRAY[item.sj] = []
							}
							FAKE_COIN_ARRAY[item.sj].push({
								dianshu: item.ds,
								shijian: item.sj,
								wanfa: item.fq1,
								/*topValue: item.top1,
								leftValue: item.left1,*/
							})
						}
						var keys = Object.keys(FAKE_COIN_ARRAY)
						for (var i = 0; i < keys.length; i++) {
						   var keyItem = keys[i]
						   if (Number(keyItem) >= ( n - 15 )) {
							   for (var j = 0; j < FAKE_COIN_ARRAY[keyItem].length; j++) {
								   var coin = FAKE_COIN_ARRAY[keyItem][j]
								   justSetCoin(coin)
							   }
						   }
						}
						var autoCreateCoinEvent = setInterval(function() {
							/*if($("#bjllot").length==0){
								clearInterval(autoCreateCoinEvent)
								return;
							}*/
							var currentTime = document.querySelector(".cutDown").innerHTML
							if (currentTime == "0") {
								clearInterval(autoCreateCoinEvent)
							}
							if (FAKE_COIN_ARRAY[currentTime] != undefined) {
								for (var i = 0; i < FAKE_COIN_ARRAY[currentTime].length; i++) {
									var item = FAKE_COIN_ARRAY[currentTime][i]
									insertStaticCoin(item)
								}
							}
						}, 1000)
					},
					error: function(status) {
					}
				}
			ajax(newRequest)			
		}
	
	
	
	
	
	
	
	
	
	//选择下注筹码
	$(".select-jetton li").on("click",function(){
		chooseIndex=$(this).index()+1
		var cutdown=$(".cutDown").text()
		if($(this).hasClass("gameCoin-large")){
			$(this).removeClass("gameCoin-large")
		}else{
			$(this).addClass("gameCoin-large").siblings().removeClass("gameCoin-large")
		}
	})
	
	var count=0;  //点击次数
	//点击次数
	var iii = 0;
	//金额
	var betsMoney = 0;
	//游戏类型
	var gameType;
	// 地址
	var address;
	//闲
	var xian = 0.00
	//庄
	var zhuang= 0.00
	//闲对
	var xiandui= 0.00
	//庄对
	var zhuangdui= 0.00
	//和
	var he=	0.00
	//大
	var big= 0.00
	//小
	var small= 0.00
	//完美对子
	var wanmeiduizi= 0.00
	//任意对子
	var randomduizi= 0.00
	
	$(".selected").on("click",function(){  //点击下注
		var index=$(this).index()+1;
		var chargeMoney=0;  //
		var that=this;
		if($(".gameCoin-large").length==0){
			return;
		}
		count++
		var cutdown=$(".cutDown").text()
		if($(".cutDown").text()<=0){
			layer.tips('已超出下注时间无法下注', '.gameCoin-large', {
                tips: [1, '#0FA6D8'], //设置tips方向和颜色 类型：Number/Array，默认：2 tips层的私有参数。支持上右下左四个方向，通过1-4进行方向设定。如tips: 3则表示在元素的下面出现。有时你还可能会定义一些颜色，可以设定tips: [1, '#c00']
                tipsMore: false, //是否允许多个tips 类型：Boolean，默认：false 允许多个意味着不会销毁之前的tips层。通过tipsMore: true开启
                time:2000, 
                skin:'tiped'
            }); 
			return;
		}
		
		var moneyNum=$(".gameCoin-large").text();  //筹码值
		var curName=$(this).attr("data-game")   //当前玩法
		var ajaxObject = {
						money: moneyNum,
						issueNumber: issueNumber,	
						xian:"",
						zhuang:"",
						xiandui:"",
						zhuangdui:"",
						he:	"",
						big:"",
						small:"",
						wanmeiduizi:"",
						renyiduizi:"",
						tableNumber: roomId,
					}
					ajaxObject[curName] = moneyNum
					var urlPath =  "/b/bjlBets.do"
					address = urlPath
		if(moneyNum=="1千"){
			moneyNum=1000;
		}if(moneyNum=="2千"){
			moneyNum=2000;
		}if(moneyNum=="5千"){
			moneyNum=5000;
		}if(moneyNum=="1万"){
			moneyNum=10000;
		}if(moneyNum=="2万"){
			moneyNum=20000;
		}if(moneyNum=="5万"){
			moneyNum=50000;
		}
		var curMoney=$(that).find(".money").text()+""
		var weishu=curMoney.substring(curMoney.length-1,curMoney.length)
		if(weishu=="千"){
			curMoney=accMul(curMoney.substring(0,curMoney.length-1),1000)
		}
		else if(weishu=="万"){
			curMoney=accMul(curMoney.substring(0,curMoney.length-1),10000)
		}
		chargeMoney=Number(curMoney)+Number(moneyNum)
		
		if(chargeMoney>=1000 && chargeMoney<10000){
			chargeMoney=chargeMoney/1000+"千"
		}else if(chargeMoney>=10000){
			chargeMoney=chargeMoney/10000+"万"
		}
		if($(".balance").val()<betsMoney+Number(moneyNum)){
			layer.alert("当前余额不足以下注，请充值后再来")
			return;
		}
		if(betsMoney == 0){
			gameType = curName;
		}if(curName == 'xian'){
			xian += parseInt(moneyNum)
		}
		if(curName == 'zhuang'){
			zhuang += parseInt(moneyNum)
		}
		if(curName == 'xiandui'){
			xiandui += parseInt(moneyNum)
		}
		if(curName == 'zhuangdui'){
			zhuangdui += parseInt(moneyNum)
		}if(curName == 'he'){
			he += parseInt(moneyNum)
		}if(curName == 'da'){
			big += parseInt(moneyNum)
		}if(curName == 'xiao'){
			small += parseInt(moneyNum)
		}if(curName == 'wanmeiduizi'){
			wanmeiduizi += parseInt(moneyNum)
		}if(curName == 'renyiduizi'){
			randomduizi += parseInt(moneyNum)
		}
		betsMoney+=Number(moneyNum)
		$(that).find(".money").text(chargeMoney)
		var newCoin = document.createElement("div")
		var $newCoin=$(newCoin)
		$newCoin.addClass("class-img-smallCoin")
		$(this).append(newCoin)
		$newCoin.css("background","url(/pc-static/img/bjl/chip"+chooseIndex+".png) no-repeat 100% 100%")
		var contentLen=$("body").height();
		var leftValue,bottomValue
		if(contentLen<876){
			leftValue=$(".gameCoin-large").offset().left+5
			bottomValue=$(".wappering").height()-$(".gameCoin-large").offset().top-90
		}else{
			leftValue=$(".gameCoin-large").offset().left+5
			bottomValue=$(".wappering").height()-$(".gameCoin-large").offset().top-40
		}
		$newCoin.css("left",leftValue+"px")
		$newCoin.css("bottom",bottomValue+"px")
		var chargeLen=$(that).find(".class-img-smallCoin").length;
		if(chargeLen>6){
			chargeLen=6
		}
		
		if(contentLen<876){
			leftValue=$(that).offset().left
			bottomValue=$(".wappering").height()-$(that).offset().top-145+chargeLen*5;
		}else{
			leftValue=$(that).offset().left+15
			bottomValue=$(".wappering").height()-$(that).offset().top-115+chargeLen*5;
		}
		setTimeout(function() {
			$newCoin.css("bottom",bottomValue+"px")
			$newCoin.css("left",leftValue+"px")
		}, 300)
		setTimeout(function() {
			$(that).find(".money").css("bottom",bottomValue+15+"px")
	        $(that).find(".money").css("left",leftValue+"px")
			$(that).find(".money").show()
		}, 1000)
	})
	
	//重新下注
	$(".cancelBet").on("click",function(){
		if(betsMoney>0){
				$(".class-img-smallCoin").css("bottom","0px")
				$(".money").text("")
				$(".money").hide();
				betsMoney=0;
				setTimeout(function() {
					$(".class-img-smallCoin").remove();
				}, 1000)
		}
		xian = 0.00
		zhuang = 0.00
		xiandui = 0.00
		zhuangdui = 0.00
		he = 0.00
		big= 0.00
		small= 0.00
		wanmeiduizi= 0.00
		randomduizi= 0.00
		count = 0;
	})
	
	
	//确认下注
	$(".confrimBet").on("click",function(){
		var cutdown=$(".cutDown").text()
		if($(".cutDown").text()<=0){
			layer.tips('已超出下注时间无法下注', '.gameCoin-large', {
                tips: [1, '#0FA6D8'], //设置tips方向和颜色 类型：Number/Array，默认：2 tips层的私有参数。支持上右下左四个方向，通过1-4进行方向设定。如tips: 3则表示在元素的下面出现。有时你还可能会定义一些颜色，可以设定tips: [1, '#c00']
                tipsMore: false, //是否允许多个tips 类型：Boolean，默认：false 允许多个意味着不会销毁之前的tips层。通过tipsMore: true开启
                time:2000, 
                skin:'tiped'
            }); 
			return;
		}
		var totalBet=xian+zhuang+xiandui+zhuangdui+he+big+small+randomduizi+wanmeiduizi;
		var xianj = ""
		var zhuangj = ""
		var zhuangd = ""
		var xiand = ""
		var hej = ""
		var daj=""
		var xiaoj=""
		var wanmeid=""
		var renyid=""
		var amountOfMoney = 0
		var cashDownAmount = 0
		var cashPairDownAmount = 0
		var zhuangdusBetOnTheAmount = 0
		var andTheAmountOfTheBet = 0
		var bigAmount = 0
		var smallAmount=0
		var perfectAmount=0
		var randomAmount=0
		if(xian > 0){
			cashDownAmount = xian
			xianj = "闲家"
		}
		if(zhuang > 0){
			amountOfMoney = zhuang
			zhuangj = "闲家"
		}
		if(xiandui > 0){
			cashPairDownAmount = xiandui
			xiand = "闲对"
		}
		if(zhuangdui > 0){
			zhuangd = "庄对"
			zhuangdusBetOnTheAmount = zhuangdui
		}
		if(he > 0){
			andTheAmountOfTheBet = he
			hej = "和"
		}if(big>0){
			bigAmount=big
			daj="大"
		}if(small>0){
			smallAmount=small
			xiaoj="小"
		}if(wanmeiduizi>0){
			perfectAmount=wanmeiduizi
			wanmeid="完美对子"
		}if(randomduizi>0){
			randomAmount=randomduizi
			renyid="任意对子"
		}
		var tableNumber = roomId
		if(totalBet <= 0){
			layer.alert("下注余额不能为空噢!")
			return
		}
		var newRequest = {
				url: address,
				type: "post",
				data: {
					issueNumber: issueNumber,	
					xian:xianj,
					zhuang:zhuangj,
					xiandui:xiand,
					zhuangdui:zhuangd,
					he:	hej,
					large:daj,
					small:xiaoj,
					arbitraryPairsx:renyid,
					perfectPairx:wanmeid,
					//庄家下注金额
					amountOfMoney:amountOfMoney,
					//闲家下注金额
					cashDownAmount:cashDownAmount,
					//闲对下注金额
					cashPairDownAmount:cashPairDownAmount,
					//庄对下注金额
					zhuangdusBetOnTheAmount:zhuangdusBetOnTheAmount,
					//和局下注金额
					andTheAmountOfTheBet:andTheAmountOfTheBet,
					//大局下注金额
					largeBetAmount:bigAmount,
					//小局下注金额
					smallBetAmount:smallAmount,
					//完美对子下注金额
					perfectPairAmount:perfectAmount,
					//任意对子下注金额
					arbitraryPairAmount:randomAmount,
					//下载总额
					totalBet: totalBet,
					tableNumber: tableNumber,
				},
				success: function(data) {
					var newData = JSON.parse(data)
					if (newData.data === 0) {
						layer.alert("下注失败")
						return
					}else if(newData.data == 2){
						layer.alert("余额不足,下注失败")
						return
					}else if(newData.data == 3){
						layer.alert("该期已结束")
						return
					}else if(newData.data == 7){
						layer.alert("亲,百家乐已关闭，请投注别的彩种把")
						return
					}else if(newData.data ==1){
					xian = 0.00
					zhuang = 0.00
					xiandui = 0.00
					zhuangdui = 0.00
					he = 0.00
					big= 0.00
					small= 0.00
					wanmeiduizi= 0.00
					randomduizi= 0.00
					count = 0;
					$(".balance").val(newData.data1)
					layer.open({
					    type: 1,
					    skin: 'layui-layer-molv',
					    area:['200px',"100px"],
					    title:false,
					    shadeClose: false, //点击遮罩关闭
					    anim: 3,
					    content: "投注成功"+totalBet+"元，祝您好运",    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
					    btn:'知道了',
					  });
					}
				},
				error: function(status) {
					layer.alert("网络异常，下注失败")
				}
			}
			ajax(newRequest)
			})

	// 发 4 张牌
		var createCardsFirst = function() {
			var contentDiv = document.querySelector(".mains")
			var offsetRightNumber
			var offsetLargeRightNumber
			var offsetLeftNumber
			var offsetLargeLeftNumber
			var i = 0
			var idObj = {
				"0": "0",
				"1": "1",
				"2": "2",
				"3": "3",
			}
			var intervalEventId = setInterval(function() {
				// 0 闲右
				// 1 闲左
				// 2 庄左
				// 3 庄右
				
					var html = 
						"<div id='id-div-cardItemDiv" + idObj[i] +"' class='viewport-flip cardItemLeft slow'><a class='list flip out beimian'><img class='class-img-pockCard' src='' /></a>"+
						"<a class='list flip zhengmian'><img class='class-img-pockCard' src='"+"/pc-static/img/bjl/print.png'  /></a>"				
				
				
				if (i == 4) {
					clearInterval(intervalEventId)
					getServerCards()
				}
				else if (i == 2) {  
					contentDiv.insertAdjacentHTML("beforeend", html)
					var cardItemRightDiv = document.querySelector("#id-div-cardItemDiv" + i)
					
						$(cardItemRightDiv).offset()
						cardItemRightDiv.style.transform = "rotate(0deg) scale(0.75)"
						cardItemRightDiv.style.top = 260 + "px"
					
					cardItemRightDiv.style.left = 860 + "px"					
				}
				else if (i == 3) { 
					contentDiv.insertAdjacentHTML("beforeend", html)
					var cardItemRightDiv = document.querySelector("#id-div-cardItemDiv" + i)
					$(cardItemRightDiv).offset()
					cardItemRightDiv.style.transform = "rotate(0deg) scale(0.75)"
					cardItemRightDiv.style.top = 260 + "px"
					cardItemRightDiv.style.left = 960 + "px"					
				}
				else if (i == 0) {
					contentDiv.insertAdjacentHTML("beforeend", html)
					var cardItemRightDiv = document.querySelector("#id-div-cardItemDiv" + i)
					$(cardItemRightDiv).offset()
						/*var topValue = getHorizontalTop()*/
						cardItemRightDiv.style.transform = "rotate(0deg) scale(0.75)"
						cardItemRightDiv.style.top = 260 + "px"
					/*var rightValue = getRight1()*/
					cardItemRightDiv.style.left =270 + "px"					
				}
				else if (i == 1) { //闲左
					contentDiv.insertAdjacentHTML("beforeend", html)
					var cardItemRightDiv = document.querySelector("#id-div-cardItemDiv" + i)
					$(cardItemRightDiv).offset()
						cardItemRightDiv.style.transform = "rotate(0deg) scale(0.75)"
						cardItemRightDiv.style.top = 260+ "px"
					cardItemRightDiv.style.left = 170 + "px"					
				}
				i = i + 1
			}, 800)
		}
	
	// 翻牌   
	   //0 庄左  
	   //1  庄右
	   //2  闲右
	   //3  闲左
	   var dealServerCards = function(newData) {
		     var cardInfoData = newData.data
		    // var dataArray = cardInfoData.split("@")
		     //var zhuangjiaArray = dataArray[0].split(",")
		     //var xianjiaArray = dataArray[1].split(",")
		     //闲家
		    /* if (xianjiaArray.length > 4) {
		    	 xianJiaBu = xianjiaArray[3]
		     }*/
		     var zeroCardItem = document.querySelector("#id-div-cardItemDiv0")
			 var oneCardItem = document.querySelector("#id-div-cardItemDiv1")
			 oneCardItem.querySelector(".out").querySelector("img").src =  "/img/caizhong/bjl/" +cardInfoData.leisure1 + ".png"
			 zeroCardItem.querySelector(".out").querySelector("img").src =  "/img/caizhong/bjl/" + cardInfoData.leisure2 + ".png" 
		     //庄家
			/* if (zhuangjiaArray.length > 4) {
		    	 zhuangJiaBu = zhuangjiaArray[3]
		     }*/
			 //获取id-div-cardItemDiv2 用于展示开出来的牌
			 var ThreeCardItem = document.querySelector("#id-div-cardItemDiv2")
			 var FourCardItem = document.querySelector("#id-div-cardItemDiv3")
			 ThreeCardItem.querySelector(".out").querySelector("img").src =  "/img/caizhong/bjl/" + cardInfoData.zhuang1 + ".png"
			 FourCardItem.querySelector(".out").querySelector("img").src =  "/img/caizhong/bjl/" + cardInfoData.zhuang2 + ".png"
			 var eleBack1 = null
			 var eleFront1 = null
			 var eleList1 = $("#id-div-cardItemDiv0 .list")
	 		 eleList1.each(function() {
		        if ($(this).hasClass("out")) {
		            eleBack1 = $(this);
		        } else {
		            eleFront1 = $(this);
		        }
		     });
		    
		     
		   /*  $("#id-div-cardItemDiv2").find(".zhengmian img").hide();
		     $("#id-div-cardItemDiv3").find(".zhengmian img").hide();*/
		     eleFront1.addClass("out").removeClass("in");
		     
		    /* */
		     setTimeout(function() {
		    	
		        eleBack1.addClass("in").removeClass("out");
		        $("#id-div-cardItemDiv0").find(".zhengmian img").hide();
		        /**/
		       /* 
			    
			    */
		     }, 225);	 
		     
		     setTimeout(function() {
				 var eleBack2 = null
				 var eleFront2 = null
				 var eleList2 = $("#id-div-cardItemDiv1 .list")
		 		 eleList2.each(function() {
			        if ($(this).hasClass("out")) {
			            eleBack2 = $(this);
			        } else {
			            eleFront2 = $(this);
			        }
			     });
			     eleFront2.addClass("out").removeClass("in");
			     
			   /* */
			     setTimeout(function() {
			    	
			        eleBack2.addClass("in").removeClass("out");
			        $("#id-div-cardItemDiv1").find(".zhengmian img").hide();
			       /* */
			     },225);	// 225	    	 
		     }, 900)//675
		   
		     setTimeout(function() {
				 var eleBack3 = null
				 var eleFront3 = null
				 var eleList3 = $("#id-div-cardItemDiv2 .list")
				 eleList3.each(function() {
			        if ($(this).hasClass("out")) {
			            eleBack3 = $(this);
			        } else {
			            eleFront3 = $(this);
			        }
			     });
			     eleFront3.addClass("out").removeClass("in");
			     setTimeout(function() {
			        eleBack3.addClass("in").removeClass("out");
			        $("#id-div-cardItemDiv2").find(".zhengmian img").hide();
			     }, 225);		    	 
		     }, 1600)//1350
		     
		     setTimeout(function() {
				 var eleBack4 = null
				 var eleFront4 = null
				 var eleList4 = $("#id-div-cardItemDiv3 .list")
		 		 eleList4.each(function() {
			        if ($(this).hasClass("out")) {
			        	eleBack4 = $(this);
			        } else {
			        	eleFront4 = $(this);
			        }
			     });
				 eleFront4.addClass("out").removeClass("in");
			     setTimeout(function() {
			        eleBack4.addClass("in").removeClass("out");
			        $("#id-div-cardItemDiv3").find(".zhengmian img").hide();
			     }, 225);		     
			     	    	 
		     }, 2400)//2025
		     
		     setTimeout(function() {
			     if (cardInfoData.leisureCard != null) {
			    	 addXianJiaCard(cardInfoData.leisureCard )
			     } 
		     }, 3200)//2700	     

		     setTimeout(function() {
			     if (cardInfoData.dealerCard != null) {
			    	 addZhuangJiaCard(cardInfoData.dealerCard )
			     } 
		     },4800)	// 4050    
		   }
			
	   
	   
	   //补闲家的牌
	   var addXianJiaCard = function(xiaJiaCard) {
		   var html = 
			"<div id='id-div-cardItemDiv" + 5 +"' class='viewport-flip cardItemLeft slow'><a class='list flip out beimian'><img class='class-img-pockCard' src='"+"/img/caizhong/bjl/" + xiaJiaCard + ".png' /></a>"+
			"<a class='list flip zhengmian'><img class='class-img-pockCard' src='"+"/pc-static/img/bjl/print.png' /></a>"	
			var contentDiv = document.querySelector(".mains")
			contentDiv.insertAdjacentHTML("beforeend", html)
				var cardItemRightDiv = document.querySelector("#id-div-cardItemDiv5")
				$(cardItemRightDiv).offset()
				cardItemRightDiv.style.transform = "rotate(90deg) scale(0.75)"
				cardItemRightDiv.style.top = 290 + "px"
				cardItemRightDiv.style.left = 145 + "px"	
			setTimeout(function() {
				 var eleBack5 = null
				 var eleFront5 = null
				 var eleList5 = $("#id-div-cardItemDiv5 .list")
		 		 eleList5.each(function() {
			        if ($(this).hasClass("out")) {
			        	eleBack5 = $(this);
			        } else {
			        	eleFront5 = $(this);
			        }
			     });
				 
				 eleFront5.addClass("out").removeClass("in");
			     setTimeout(function() {
			        eleBack5.addClass("in").removeClass("out");
			        $("#id-div-cardItemDiv5").find(".zhengmian img").hide();
			     }, 225);					
			}, 1000)
		}
	   
	   //补庄家的牌
	   var addZhuangJiaCard = function(zhuangjiaCard) {
		   var html = 
			"<div id='id-div-cardItemDiv" + 6 +"' class='viewport-flip cardItemLeft slow'><a class='list flip out beimian'><img class='class-img-pockCard' src='"+"/img/caizhong/bjl/" + zhuangjiaCard + ".png' /></a>" +
			"<a class='list flip zhengmian'><img class='class-img-pockCard' src='"+"/pc-static/img/bjl/print.png' /></a>"	
			var contentDiv = document.querySelector(".mains")
			contentDiv.insertAdjacentHTML("beforeend", html)
			var cardItemRightDiv = document.querySelector("#id-div-cardItemDiv6")
			$(cardItemRightDiv).offset()
			cardItemRightDiv.style.transform = "rotate(90deg) scale(0.75)"
			cardItemRightDiv.style.left = 1170 + "px"	
			cardItemRightDiv.style.top =290 + "px"
			setTimeout(function() {
				 var eleBack6 = null
				 var eleFront6 = null
				 var eleList6 = $("#id-div-cardItemDiv6 .list")
		 		 eleList6.each(function() {
			        if ($(this).hasClass("out")) {
			        	eleBack6 = $(this);
			        } else {
			        	eleFront6 = $(this);
			        }
			     });
				 eleFront6.addClass("out").removeClass("in");
				
			     setTimeout(function() {
			        eleBack6.addClass("in").removeClass("out");
			        $("#id-div-cardItemDiv6").find(".zhengmian img").hide();
			     }, 225);					
			}, 1000)			
		}
	 
	   
	 //直接展示 4 张牌，因为用户进来的时候牌已经发好了
		var notNoralToAddFourCard = function(data) {
			//var dataArray = data.split("@")
		    //庄家
			//var zhuangjiaArray = dataArray[0].split(",")
		    //闲家
			//var xianjiaArray = dataArray[1].split(",")
		    var item1 = document.createElement("img")
		    var item2 = document.createElement("img")
		    var item3 = document.createElement("img")
		    var item4 = document.createElement("img")
		    var itemsArray = [item1, item2, item3, item4]
		    item1.style.left = "170px"
		    item2.style.left = "270px"
		    item3.style.left = "860px"
		    item4.style.left ="960px"
		    var topValue
		   /* if (isHorizontalScreen()) {
				topValue = getHorizontalTop()
		    } else {
		    	topValue = getVerticalTop()
		    }*/
			for (var i = 0; i < itemsArray.length; i++) {
				var newItem = itemsArray[i]
				newItem.style.top = "260px"
				newItem.style.transform = "rotate(0deg) scale(1)"
				newItem.classList.add("cardItemRight")
			}							  
		    item1.src = "/img/caizhong/bjl/" + data.leisure2 + ".png"
		    item2.src = "/img/caizhong/bjl/" + data.leisure1 + ".png"
		    item3.src = "/img/caizhong/bjl/" + data.zhuang1 + ".png"
		    item4.src = "/img/caizhong/bjl/" + data.zhuang2 + ".png"
		    var contentDiv = document.querySelector(".mains")
		    contentDiv.insertAdjacentElement("beforeend", item1)
		    contentDiv.insertAdjacentElement("beforeend", item2)
		    contentDiv.insertAdjacentElement("beforeend", item3)
		    contentDiv.insertAdjacentElement("beforeend", item4)
		     if (data.leisureCard != null) {
		    	 xianJiaBu = data.leisureCard
		     }
		     if (data.dealerCard != null) {
		    	 zhuangJiaBu = data.dealerCard
		     }				
		}
	   
	   
	// 直接插入闲家的补牌，因为用户进来的时候，补牌已经补好了 
		var notNoralToAddFiveCard = function(xianJiaBuData) {
			 var item5 = document.createElement("img")
	   	 item5.src = "/img/caizhong/bjl/" + xianJiaBuData + ".png"
	   	 item5.style.right =260 + "px"
	   	 item5.style.top = 260 + "px"
	   	 item5.style.transform = "rotate(0deg) scale(1)"
	   	 item5.classList.add("cardItemRight")
	   	 var contentDiv = document.querySelector(".mains")
	   	 contentDiv.insertAdjacentElement("beforeend", item5)			
		}
		
		// 直接插入庄家的补牌，因为用户进来的时候，补牌已经补好了 
		var notNoralToAddSixCard = function(zhuangJiaBuData) {
	   	 var item6 = document.createElement("img")
	   	 item6.src = "/img/caizhong/bjl/" + zhuangJiaBuData + ".png"
	   	 item6.style.right = 260 + "px"
	   	 item6.style.top = 260 + "px"
	   	 item6.style.transform = "rotate(0deg) scale(1)"
	   	 item6.classList.add("cardItemRight")
	   	 var contentDiv = document.querySelector(".mains")
	   	 contentDiv.insertAdjacentElement("beforeend", item6)		
		}
		
		
		
		// 赢的结果高亮
		var settingResultDivHighLight = function() {
			if(isIphone){
				MUSIC_PATH =  "/music/"
			} else {
				MUSIC_PATH =  "/music/android/"
		    }
			// var newDataArray = zhuangXianArray.data.split("@")
			 var newDataArray = zhuangXianArray
			 //拿到赢家
			// var resultWin = newDataArray[newDataArray.length - 2]
			 var resultWin
			 if(newDataArray.data.winner == 0){
				  resultWin = "闲赢"
			 }else if(newDataArray.data.winner == 1){
				  resultWin = "庄赢"
			 }else if(newDataArray.data.winner == 2){
				  resultWin = "和局"
			 }
			 // var zhuangjiaArray = newDataArray[0].split(",")
			
			 //抛开数据的地方 闲  fangpj,meiha,1,meih9,0,
			
			 // var xianjiaArray = newDataArray[1].split(",")
			 //bjl.getZhuang() + "@" + bjl.getXian() + "@" + bjl.getYingjia() + "@" + bjl.getDuizhi();
//			 zhuangDianShu = zhuangjiaArray[zhuangjiaArray.length - 2]
			 zhuangDianShu = newDataArray.data.makerSFinalPoints
			
			// xianDianShu = xianjiaArray[xianjiaArray.length - 2]
			 xianDianShu = newDataArray.data.leisureHomePoints
			 
			 yingResultText = yingMusicObject[resultWin]
	  			XIAN_SOUND = new Howl({
	 			  src: [MUSIC_PATH + "x" + xianDianShu + ".mp3"]
	 			});
	 			ZHUANG_SOUND = new Howl({
	 			  src: [MUSIC_PATH + "z" + zhuangDianShu + ".mp3"]
	 			});
	 			RESULT_SOUND = new Howl({
	 			  src: [MUSIC_PATH + yingResultText]
	 			});
	 			 if($(".systemSound").find(".onSound").length==1){
		 				XIAN_SOUND.on("end", function(id) {
			 				ZHUANG_SOUND.play()
			 			})
			 			ZHUANG_SOUND.on("end", function(id) {
			 				RESULT_SOUND.play()
			 			})
			 			XIAN_SOUND.play()
				   }
	 			
	 			$(".zhuangBox").text(zhuangDianShu)
	 			$(".xianBox").text(xianDianShu)
	 			/*document.querySelector("#id-span-zhuang-resultCount").innerHTML = zhuangDianShu
	 			document.querySelector("#id-span-xian-resultCount").innerHTML = xianDianShu	*/	
	 			var winDivPicker = yingObject[resultWin]
			    var winDiv = document.querySelector(winDivPicker)
			    winDiv.classList.add("class-getResultHightLightDiv")
			    if(newDataArray.data.size==0){
			    	$(".small").addClass("class-getResultHightLightDiv")
			    }else{
			    	$(".big").addClass("class-getResultHightLightDiv")	
			    }
				if(newDataArray.data.arbitraryPairs==1){
					$(".randomPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.perfectPair==1){
					$(".perfectPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.zhuangPairs==1){
					$(".zhuangPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.idleTime==1){
					$(".xianPair").addClass("class-getResultHightLightDiv")
				}
	 			setTimeout(function(){$(".selected").removeClass("class-getResultHightLightDiv")}, 500);
	 			setTimeout(function(){ if(newDataArray.data.size==0){
			    	$(".small").addClass("class-getResultHightLightDiv")
			    }else{
			    	$(".big").addClass("class-getResultHightLightDiv")	
			    }
				if(newDataArray.data.arbitraryPairs==1){
					$(".randomPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.perfectPair==1){
					$(".perfectPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.zhuangPairs==1){
					$(".zhuangPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.idleTime==1){
					$(".xianPair").addClass("class-getResultHightLightDiv")
				}
				winDiv.classList.add("class-getResultHightLightDiv")}, 1000);
	 			setTimeout(function(){$(".selected").removeClass("class-getResultHightLightDiv")},1500);
	 			setTimeout(function(){ if(newDataArray.data.size==0){
			    	$(".small").addClass("class-getResultHightLightDiv")
			    }else{
			    	$(".big").addClass("class-getResultHightLightDiv")	
			    }
				if(newDataArray.data.arbitraryPairs==1){
					$(".randomPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.perfectPair==1){
					$(".perfectPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.zhuangPairs==1){
					$(".zhuangPair").addClass("class-getResultHightLightDiv")
				}
				
				if(newDataArray.data.idleTime==1){
					$(".xianPair").addClass("class-getResultHightLightDiv")
				}
				winDiv.classList.add("class-getResultHightLightDiv")}, 2000);
				zhuangXianArray = []
				xianJiaBu = undefined
				zhuangJiaBu	= undefined	
				if($("#notice div").text()!="null"){
					$("#notice").fadeIn("slow")
				}
		}
		
		
		// 清空上把的点数和高亮的结果 div
		var removeHighLightClassAndNumber = function() {
				$(".xianBox").text("")
				$(".zhuangBox").text("")
				/*$(".selected").removeClass(".class-getResultHightLightDiv")*/
				var highLightDiv = document.querySelectorAll(".class-getResultHightLightDiv")
				for(i=0;i<highLightDiv.length;i++){
					$(highLightDiv[i]).removeClass("class-getResultHightLightDiv");
				}
				/*$(".class-getResultHightLightDiv").remove();*/
				/*document.querySelector("#id-span-zhuang-resultCount").innerHTML = ""
				document.querySelector("#id-span-xian-resultCount").innerHTML = ""*/
				/*var highLightDiv = document.querySelectorAll(".class-getResultHightLightDiv")
				if (highLightDiv != null) {
					$(highLightDiv).removeClass("class-getResultHightLightDiv")
				}*/
		}
		
		
		// 移除所有这把的扑克牌
		   var removeAllCards = function() {
				var allCards = document.querySelectorAll(".cardItemLeft")
				for (var i = 0; i < allCards.length; i++) {
					var item = allCards[i]
					$(item).css("transform","rotate(0deg) scale(1)")
					$(item).find(".zhengmian").removeClass("out")
					$(item).find(".beimian").removeClass("in").addClass("out")
					$(item).find(".beimian").find(".class-img-pockCard").hide()
					$(item).find(".zhengmian").find(".class-img-pockCard").show()
					
					
					if($(item).attr("id")=="id-div-cardItemDiv5"){
						$(item).css("transform","rotate(0deg) scale(1)")
					}
					if($(item).attr("id")=="id-div-cardItemDiv6"){
						$(item).css("transform","rotate(0deg) scale(1)")
					}
					$(item).removeClass("slow")
					item.style.left ="680px"
					item.style.top ="140px"
					$(item).find(".class-img-pockCard").css("width","100px")
					$(item).find(".class-img-pockCard").css("height","144px")
					
				}
				var pockCard=document.querySelectorAll(".class-img-pockCard")
				for(var i=0;i<pockCard.length;i++){
					var item=pockCard[i]
					setTimeout(function(){$(item).remove();},1000)
				}
				var smallCoins = document.querySelectorAll(".class-img-mygameCoin")
				for (var q = 0; q < smallCoins.length; q++ ) {
					var item = smallCoins[q]
				}	
				setTimeout(function() {
					for (var q = 0; q < smallCoins.length; q++ ) {
						var item = smallCoins[q]
						$(item).remove()
					}				
				}, 500) 			
				setTimeout(function() {
				for (var i = 0; i < allCards.length; i++) {
					var item = allCards[i]
				}					
				}, 500) 		
				setTimeout(function() {
					for (var i = 0; i < allCards.length; i++) {
						var item = allCards[i]
						$(item).remove()
					}					
				}, 1000) 
				$("#notice").fadeOut("slow")
			}
		
		   
	//显示历史数据
	function drawData(){
		$.ajax({ 
		 	url:"/b/history.do", 
		 	type:"post", 
		 	data: {tableNumber: roomId}, 
		 	success:function(data){ 
		 		$(".kaijiangjl").empty();
		 		$(".zhuangxianjl").empty();  //庄闲的数据
		 		$(".sizejl").empty();   //大小的数据
		 		$(".history").empty();
		 		var newData=data.data
		 		var html="";
		 		var html1=""
		 		var h=[];
		 		var zhuangNum=0;  //庄的数量
		 		var xianNum=0;   //闲的数量
		 		var heNum=0;    //和的数量
		 		var zhuangduiNum=0;   //庄对的数量
		 		var xianduiNum=0;   //闲对的数量
		 		var LynnArr=[];//庄闲记录的数组
		 		var pairArr=[]; //庄闲对的数组
		 		var SizeArr=[];//大小的数组
		 		/*var h = "";*/
		 		var conunt = 0;
		 		for(i=newData.length-1;i>=0;i--){
		 			if(newData[i].winner==0){
		 				/*h+="span2";*/
		 				h.push("span2")
		 				LynnArr.push("闲")
		 				xianNum++
		 			/*	h.push("闲")*/
		 			}else if(newData[i].winner==1){
		 				/*h+="span1";*/
		 				h.push("span1")
		 				LynnArr.push("庄")
		 				zhuangNum++
		 				/*h.push("庄")*/
		 			}else{
		 			/*	h+="和"*/
		 				h.push("和")
		 				LynnArr.push("和")
		 				heNum++
		 			}
		 			if(newData[i].size==0){
		 				SizeArr.push("小")
		 			}else{
		 				SizeArr.push("大")
		 			}
		 			
		 			
		 			if(newData[i].zhuangPairs==1){
		 				pairArr.push("庄对")
		 				zhuangduiNum++
		 			}
		 			if(newData[i].idleTime==1){
		 				pairArr.push("闲对")
		 				xianduiNum++
		 			}else if(newData[i].zhuangPairs!=1 && newData[i].idleTime!=1 ){
		 				pairArr.push("")
		 			}
		 		}
		 		var xLynn=split_array(LynnArr, 6);
		 		var xPair=split_array(pairArr, 6);
		 		var xSize=split_array(SizeArr, 6);
		 		$(".zhuangNum").text(zhuangNum)
		 		$(".xianNum").text(xianNum)
		 		$(".heNum").text(heNum)
		 		$(".zhuangduiNum").text(zhuangduiNum)
		 		$(".xinaduiNum").text(xianduiNum)
		 		var lynnHtml="";
		 		var sizeHtml=""
		 		for(i=0;i<xLynn.length;i++){
		 			lynnHtml+="<div class='item1'>"
		 			sizeHtml+="<div class='item1'>"
		 			for(j=0;j<xLynn[i].length;j++){
		 				if(xLynn[i][j]=="庄"){
		 					if(xPair[i][j]=="庄对"){
		 						lynnHtml+="<div class='item'><span class='zhuang'>庄</span><em class='zhuangpair'></em></div>"
			 				}else if(xPair[i][j]=="闲对"){
			 					lynnHtml+="<div class='item'><span class='zhuang'>庄</span><em class='xianpair'></em></div>"
			 				}else{
			 					lynnHtml+="<div class='item'><span class='zhuang'>庄</span></div>"
			 				}
		 				}
		 				else if(xLynn[i][j]=="闲"){
		 					if(xPair[i][j]=="庄对"){
		 						lynnHtml+="<div class='item'><span class='xian'>闲</span><em class='zhuangpair'></em></div>"
			 				}else if(xPair[i][j]=="闲对"){
			 					lynnHtml+="<div class='item'><span class='xian'>闲</span><em class='xianpair'></em></div>"
			 				}else{
			 					lynnHtml+="<div class='item'><span class='xian'>闲</span></div>"
			 				}	
		 				}else{
		 					if(xPair[i][j]=="庄对"){
		 						lynnHtml+="<div class='item'><span class='hu'>和</span><em class='zhuangpair'></em></div>"
			 				}else if(xPair[i][j]=="闲对"){
			 					lynnHtml+="<div class='item'><span class='hu'>和</span><em class='xianpair'></em></div>"
			 				}else{
			 					lynnHtml+="<div class='item'><span class='hu'>和</span></div>"
			 				}	
		 				}
		 				
		 				if(xSize[i][j]=="小"){
		 					sizeHtml+="<div class='item'><span class='small'>小</span></div>"
		 				}else{
		 					sizeHtml+="<div class='item'><span class='large'>大</span></div>"
		 				}
		 			}
		 			lynnHtml+="</div>"
		 			sizeHtml+="</div>"
		 		}
		 		
		 		for(var i=0;i<11-xLynn.length;i++){
		 			lynnHtml+="<div class='item1'>"
		 			sizeHtml+="<div class='item1'>" 
			 			for(var j=0;j<6;j++){ 
			 				//这个什么都没有的
			 				lynnHtml+="<div class='item'><span class='span'></span></div>";
			 				sizeHtml+="<div class='item'><span class='span'></span></div>";
			 			} 
		 			lynnHtml+="</div>"
		 			sizeHtml+="</div>"
		 		}
		 		$(".zhuangxianjl").append(lynnHtml);  //庄闲的数据
		 		$(".sizejl").append(sizeHtml);   //大小的数据
		 		var t=""
		 		var n=""
		 		/*var state=0  // 0代表和出现和的前一个状态一样，1代表不一样
		 			for(var i=0;i<h.length;i++){
		 				if(h[0]=="和"){
		 					
		 					break;
		 				}else{
		 					if(h[0]=="闲"){
		 						
		 					}
		 					
		 					if(h[i]!=h[i-1] && h[i]!="和"){
		 						n+=";"
		 					}
		 					
		 					if(h[i]=="和"){
		 						state=h[i-1];
		 					}
		 				}
		 			}*/
		 			var state=""  // 0代表和出现和的前一个状态一样，1代表不一样
		 		for(var i=0;i<h.length;i++){
		 			if(h[i]!=h[i-1] && h[i]!="和" && h[i]!=state){
		 					n+="@"
		 			}
		 			if(h[i]=="和"){
		 				n+=h[i]
		 			}else{
		 				state=h[i]
		 				n+=","+h[i]	
		 			}
		 		}
		 		n=n.split("@,")
		 		for(i=1;i<n.length;i++){
		 			html+="<div class='item1'>"
		 			var nl=n[i].split(",")
		 			for(var j=0;j<nl.length;j++){
		 				if(nl[j].length>5){
		 					var helen=nl[j].length-5
		 					//有和的
		 					html+="<div class='item'><span class='"+nl[j].substring(0,5)+"'></span><em class='he"+helen+"'></em></div>";
		 				}else{
		 					//这个是没有和的
		 					html+="<div class='item'><span class='"+nl[j]+"'></span></div>"; 	
		 				}
		 			}
		 			for(var j=0;j<6-nl.length;j++){
		 				//这个是什么都没有的
		 				html+="<div class='item'><span class='span'></span></div>"; 
		 			} 
		 			html+="</div>"
		 		}
		 		for(var i=0;i<36-n.length+1;i++){
		 			html+="<div class='item1'>" 
			 			for(var j=0;j<6;j++){ 
			 				//这个什么都没有的
			 				html+="<div class='item'><span class='span'></span></div>"; 
			 			} 
			 			html+="</div>"
		 		}
		 		$(".history").html(html)
		 		
		 		
	/*	 		for(i=data.data.length-1;i>=0;i--){
		 			var item=data.data[i];
		 			var ff=data.data[i+1];//他上一次的值
		 			//先判断他是否等于庄   如果等于庄 那么我就进去  等于他一下
		 			//如果不等于走esle if() 判断他是否等于闲
		 			// 如果他不等于闲  我又干什么。。。。。
		 			
		 			
		 			*//**
		 			 * 第一个点直接画  第二个点看上一个点和他是不是一样的  如果是继续往下面画   
		 			 * 如果不是 那就看一下他是不是和  如果是 就不跳行  也不继续往下   在原来的地方画一个杠   下一个还是和的话 一样的在原来的地方画一个杠
		 			 * 
		 			 * 如果他不等于和   那就跳行
		 			 * 
		 			 *//*
		 			
		 			if(ff != undefined){
		 				//第二个看他是否等于上一个   如果等于那就继续画  如果不等于那就 看一下他是不是和
		 				if(ff.winner == item.winner && item.winner != 2){//等于接着画
		 					if(item.winner==0){
			 					h+=",span2"//闲家
			 				}else{
			 					h+=",span1"//庄家
			 				}
		 				}else{//如果不等于那就 看一下他是不是和
		 					if(ff.winner == 2){
		 						//那么要拿他的上上个来和现在的对比，如果不等于那就不管 换行 如果等于那就换列
		 						if(data.data[i+2].winner != 2){
		 							if(data.data[i+2].winner == item.winner){
			 							if(item.winner==0){
						 					h+=",span2"//闲家
						 				}else{
						 					h+=",span1"//庄家
						 				}
			 						}else{
			 							if(item.winner==0){
			 								h+=";span2"//闲家
			 							}else{
			 								h+=";span1"//庄家
			 							}	
			 						}
		 						}else{
		 							if(data.data[i+3].winner != 2){
		 								if(data.data[i+3].winner == item.winner){
		 									if(item.winner==0){
		 										h+=",span2"//闲家
		 									}else{
		 										h+=",span1"//庄家
		 									}
		 								}else{
		 									if(item.winner==0){
		 										h+=";span2"//闲家
		 									}else{
		 										h+=";span1"//庄家
		 									}	
		 								}
		 							}else{
		 								if(data.data[i+4].winner != 2){
		 									if(data.data[i+4].winner == item.winner){
		 										if(item.winner==0){
		 											h+=",span2"//闲家
		 										}else{
		 											h+=",span1"//庄家
		 										}
		 									}else{
		 										if(item.winner==0){
		 											h+=";span2"//闲家
		 										}else{
		 											h+=";span1"//庄家
		 										}	
		 									}
		 								}else{
		 									if(data.data[i+5].winner != 2){
		 										if(data.data[i+5].winner == item.winner){
			 										if(item.winner==0){
			 											h+=",span2"//闲家
			 										}else{
			 											h+=",span1"//庄家
			 										}
			 									}else{
			 										if(item.winner==0){
			 											h+=";span2"//闲家
			 										}else{
			 											h+=";span1"//庄家
			 										}	
			 									}
		 									}else{
		 										if(data.data[i+6].winner == item.winner){
			 										if(item.winner==0){
			 											h+=",span2"//闲家
			 										}else{
			 											h+=",span1"//庄家
			 										}
			 									}else{
			 										if(item.winner==0){
			 											h+=";span2"//闲家
			 										}else{
			 											h+=";span1"//庄家
			 										}	
			 									}
		 									}
		 								}
		 							}
		 						}
		 					}else{
		 						if(item.winner==2){
		 							h+=" he"//和
		 						}else{ ///如果他不是和那就 换行
		 							if(item.winner==0){
		 								h+=";span2"//闲家
		 							}else{
		 								h+=";span1"//庄家
		 							}	
		 						}
		 					}
		 				}
		 			}else{
		 				//第一个直接画
		 				if(item.winner==0){
		 					h+="span2"//闲家
		 				}else{
		 					h+="span1"//庄家
		 				}
		 			}
		 		}
		 		return;*/
		 		
		 	}
		})
	}
			
			
	
	
	//返回值：arg1乘以arg2的精确结果
	function accMul(arg1,arg2)
	{
	 var m=0,s1=arg1.toString(),s2=arg2.toString();
	 try{m+=s1.split(".")[1].length}catch(e){}
	 try{m+=s2.split(".")[1].length}catch(e){}
	 return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
	}
	

	
	
	//播放器兼容处理
	 function playAuto(ele) {
	     document.addEventListener('WeixinJSBridgeReady', function (evt) {
	             ele.play();
	     }, false);
	 }
	 
	 
	 function split_array(arr, len){  //将一个大数组分成若干小数组
		 var a_len = arr.length;
		 var result = [];
		 for(var i=0;i<a_len;i+=len){
			 result.push(arr.slice(i,i+len));
			 }
		 return result;
	}